<!--子页面-->
<?php
use yii\helpers\Html;
use yii\helpers\Url;
?>
<style type="text/css">
    .td-with{
        border-collapse: collapse;
        table-layout:fixed;
    }
    .td-with tbody tr td{
        text-overflow:ellipsis;
        overflow:hidden;
        white-space: nowrap;
    }
</style>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>系统配置</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group form-horizontal form-style">
                        <?php
                        $items[] = [
                            'label' => '普通配置',
                            'url'=>Url::current(['class'=>1,'page'=>1]),
                            'active' => $class == 1
                        ];
                        if(Yii::$app->user->id == 1){
                            $items[] = [
                                'label' => '系统配置',
                                'url'=>Url::current(['class'=>0,'page'=>1]),
                                'active' => $class == 0
                            ];
                        }
                        $items[] = [
                            'label' => 'APP版本配置',
                            'url'=>Url::current(['class'=>'app_version','page'=>1]),
                            'active' => $class == 'app_version'
                        ];
                        echo \yii\bootstrap\Tabs::widget(['items'=>$items]); ?>
                    </div>
                    <div class="form-group form-horizontal form-style">
                        <div class="row m-b">
                            <div class="col-sm-2">
                                <?php if($this->context->isAuth('config/edit-ajax-do')){?><button type="button" class="btn btn-primary edit_config">添加配置</button><?php }?>
                                <button type="button" class="btn btn-success refresh_cache">刷新缓存</button>
                            </div>
                        </div>
                    </div>
                    <table class="table table-striped table-bordered table-hover dataTables-example class_table td-with">
                        <thead>
                        <tr class="tb-title">
                            <th class="text-center">ID</th>
                            <th class="text-center" style="width: 20%">键</th>
                            <th class="text-center" style="width: 25%">值</th>
                            <th class="text-center" style="width: 25%">说明</th>
                            <th class="text-center">状态</th>
                            <th class="text-center">更新时间</th>
                            <th class="text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                            <?php if(!empty($list)) foreach($list as $item){ ?>
                            <tr data-id="<?=$item->id?>">
                                <td><?=$item->id?></td>
                                <td style="font-weight: bold;"><?=$item->key?></td>
                                <td style="font-weight: bold;white-space: normal;"><?=$item->value?></td>
                                <td style="color:#b4b4b4"><?=$item->explain?></td>
                                <td align="center">
                                    <?php if($this->context->isAuth('config/status-ajax-do')){ ?>
                                        <?= $item->status == 0?'<a href="javascript:;" class="btn btn-xs btn-warning ajax_action" data-status="1" tip="解禁" url="status-ajax-do">禁用</a>':'<a href="javascript:;" class="btn btn-xs btn-primary ajax_action" data-status="0" tip="禁用" url="status-ajax-do">正常</a>' ?>
                                    <?php }else{?>
                                        <?= $item->status == 0?'禁用':'正常'?>
                                    <?php }?>
                                </td>
                                <td><?=date('Y-m-d H:i',$item->update_time)?></td>
                                <td>
                                    <?php if($this->context->isAuth('config/edit-ajax-do')){ ?>
                                        <a href="javascript:;" data-id="<?=$item->id?>" data-key="<?=$item->key?>" data-class="<?=$item->class?>" data-value="<?=$item->value?>" data-explain="<?=$item->explain?>" class="btn btn-xs btn-primary edit_config">编辑</a>
                                    <?php }?>
                                </td>
                            </tr>
                            <?php }?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!--添加编辑课程-->
    <div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title">编辑配置</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="ibox float-e-margins">
                                <div class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><span class="text-danger">*</span>类别：</label>
                                        <div class="col-sm-2">
                                            <select name="class" class="form-control">
                                                <option value="0" <?=Yii::$app->user->id != 1?'disabled':''?>>系统配置</option>
                                                <option value="1">普通配置</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><span class="text-danger">*</span>键：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="key" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><span class="text-danger">*</span>值：</label>
                                        <div class="col-sm-7">
                                            <input type="text" class="form-control" name="value" />
                                        </div>
                                        <div class="col-sm-2">
                                            <button class="btn btn-defulat ajaxUpload" id="upload_image" value="">使用图片</button>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">说明：</label>
                                        <div class="col-sm-8">
                                            <input type="text" class="form-control" name="explain" />
                                        </div>
                                    </div>
                                    <input type="hidden" name="id" value="0" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary editconfig" data-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--js-->
<script type="text/javascript" src="/js/plugins/plupload-2.1.2/plupload.full.min.js"></script>
<script type="text/javascript" src="/js/plugins/plupload-2.1.2/oss_upload.js" ></script>
<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript">

    $(function(){

        $(".edit_config").click(function(){
            var id = $(this).attr('data-id');
            var key='';
            var value='';
            var explain='';
            var class_val='0';
            if(id == undefined){
                id=0;
            }else{
                key = $(this).attr('data-key');
                value = $(this).attr('data-value');
                explain = $(this).attr('data-explain');
                class_val = $(this).attr('data-class');
            }
            $("#myModal1 input[name=id]").val(id);
            $("#myModal1 input[name=key]").val(key).prop('disabled',id?true:false);
            $("#myModal1 input[name=value]").val(value);
            $("#myModal1 input[name=explain]").val(explain);
            $("#myModal1 select[name=class] option[value="+class_val+"]").prop('selected',true);
            $('#myModal1').modal('show').find('.modal-title').text((id?'编辑':'添加')+'配置');
        });

        $(".editconfig").click(function(){
            var id= $("#myModal1 input[name=id]").val();
            var key= $("#myModal1 input[name=key]").val();
            var value= $("#myModal1 input[name=value]").val();
            var explain= $("#myModal1 input[name=explain]").val();
            var class_val= $("#myModal1 select[name=class]").val();
            $.ajax({
                type: "post",
                url: "edit-ajax-do",
                data: {id:id,key:key,value:value,explain:explain,'class':class_val},
                dataType: "json",
                success: function(param){
                    if(param.code == '20000'){
                        alert(param.message);
                        location.reload();
                    }else{
                        alert(param.message);
                    }
                }
            });
        });

        $('.refresh_cache').click(function(){
            $.ajax({
                type: "post",
                url: "list",
                data: {refresh:1},
                dataType: "json",
                success: function(param){
                    if(param.code == '20000'){
                        alert(param.message);
                    }else{
                        alert(param.message);
                    }
                }
            });
        })
    });
    var ossUpload = <?=$ossUpload?>;
    upload_image({
        'browse_button':'upload_image'
    },function(up, file, info){
        var host = '<?=\backend\utils\ImageSize::get_base_url()?>';
        $('input[name="value"]').val(host+g_object_name);
    });
</script>
<!--js-->
<!--/子页面-->


